package com.css.zfzx.fwsjcj.config.image;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class SourceConfiguration implements WebMvcConfigurer {
    @Autowired
    private ConfigBeanValue configBeanValue;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * @Description: 对文件的路径进行配置,创建一个虚拟路径/file/**
         *这是图片的物理路径 "file:/+本地图片的地址"
         * @Date： Create in 21:36 2018/11/08
         */
        //本地
//        String url = "D:/images/";
        //线上
        String url = "/opt/images/";
        String virtualPath = configBeanValue.virtualPath + "/**";
        registry.addResourceHandler(virtualPath).addResourceLocations("file:"+url);
    }
}
